#ifndef KEYRECOMMANDER_H
#define KEYRECOMMANDER_H

#include<iostream>
#include <string>
#include <queue>
#include <set>
#include <vector>
#include <memory>
//#include "TcpConnection.h" // 假设存在TcpConnection类

// 自定义的结果结构体
struct MyResult {
    std::string _word;
    int _freq;
    int _dist;
};

// 自定义的比较函数
struct MyCompare {
    bool operator()(const MyResult& lhs, const MyResult& rhs) {
        if (lhs._dist != rhs._dist) {
            return lhs._dist > rhs._dist;
        } else if (lhs._freq != rhs._freq) {
            return lhs._freq < rhs._freq;
        } else {
            return lhs._word < rhs._word;
        }
    }
};


class KeyRecommander {
using TcpConnectionPtr = std::ostream;
public:
    KeyRecommander(const std::string& query);
    //输出推荐的关键词
    std::vector<std::string> execute(); 
    //
    void queryIndexTable(std::string word);
    //
    int distance(const std::string& word1 , const std::string& word2);

    //
    size_t nBytesCode(const char ch);
    //
    std::size_t length(const std::string &str);
    //
    int triple_min(const int &a, const int &b, const int &c);
    //
    void mergeVectors(const std::vector<std::vector<std::string>>& vectors);

public:
    //
    std::vector<std::string> _queryWords;
    //
    std::vector<std::string> _splitedStrings;
    //
    std::vector<std::string> _mergedVector;
    //
    std::set<int> _AssociatedWords;
};

#endif // KEYRECOMMANDER_H
